﻿#!/usr/bin/env python
# Gamescript.py: Alien Xenocide game story script
# 24/06/09
# Copyright(c) 2009 Victor Freire e Cássio Espindola. All rights reserved.
# Python 2.6.2
import random

import Maps
import Defines
import Sound

#Storyline, etc
class GameDirectorClass:
    #def __init__(self):
    #    self.new_game()
    def new_game(self, player):
        self.number_of_maps = Defines.NUMBER_OF_DECKS
        self.current_map = 0
        self.change_map(self.current_map)
        pos = Maps.Maps.get_start_pos('map%d' % self.current_map)
        player.x = pos[0]
        player.y = pos[1]
                
        
    def found_exit(self, player):
        if self.current_map < (self.number_of_maps - 1):
            self.current_map += 1
            pos = Maps.Maps.get_start_pos('map%d' % self.current_map)
            player.x = pos[0]
            player.y = pos[1]
            player.angle = Defines.MAP_START_POS_ANGLE
            self.change_map(self.current_map)
        else:
            pass #print 'game finished'
            
            
    def change_map(self, number):
        if number >= self.number_of_maps:
            return False
        mapname = 'map%d' % self.current_map
        Maps.Maps.set_current_map(mapname)
        # load monsters
        self.objects = []
        self.objects = Maps.Maps.get_objects(mapname)[:]
        SoundDirector.map_changed()
        

class SoundDirectorClass:
    def __init__(self):
        self.soundcfg = {'aliendeath': 2,
                         'alienlaser': 4,
                         'alienlaugh': 0,
                         'playerhit': 1}
        pass
    
    def map_changed(self):
        Sound.Sound.play_music('map%d' % GameDirector.current_map)
        
    def sound_event(self, snd):
        if snd in ('aliendeath', 'alienlaser', 'playerhit'):
            Sound.Sound.play_sound(snd + str(random.randint(0, self.soundcfg[snd])))
        elif snd == 'playerdeath':
            Sound.Sound.play_sound('alienlaugh' + str(random.randint(0, self.soundcfg['alienlaugh'])))
            Sound.Sound.play_sound('playerdeath')
        else:
            Sound.Sound.play_sound(snd)
        
            
            
SoundDirector = SoundDirectorClass()
GameDirector = GameDirectorClass()
            
        
        
    
    
